

class Solution {
public:
    ListNode* removeNthFromEnd(ListNode* head, int n) {
        ListNode*left=new ListNode(0);
        left->next=head;
        ListNode*right=left;
        ListNode*newhead=left;

        while(n--)
        {
            right=right->next;
        }
        while(right->next)
        {
            left=left->next;
            right=right->next;
        }
        ListNode*next=left->next;
        left->next=left->next->next;
        delete next;
        return newhead->next;
    }
};